package com.sky.controller.query;

import com.sky.entity.MRdata;
import com.sky.service.DatabaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class QueryController {

    @Autowired
    private DatabaseService databaseService;

    @PostMapping("/query")
    public ResponseEntity<MRdata> queryDatabase(@RequestBody Map<String, String> request) {
        String param = request.get("param");
        try {
            List<Map<String, Object>> results = databaseService.queryData(param);
            return ResponseEntity.ok(new MRdata(true, "查询成功", results));
        } catch (Exception e) {
            return ResponseEntity.status(500)
                    .body(new MRdata(false, "查询失败: " + e.getMessage(), null));
        }
    }
}
